Skip to content

fix(react-router): Forward redirect URL options from middleware to client state#8622

Merged
wobsoriano merged 3 commits into
mainfrom
rob/fix-react-router-redirect-urls
May 22, 2026
Merged

fix(react-router): Forward redirect URL options from middleware to client state#8622
wobsoriano merged 3 commits into
mainfrom
rob/fix-react-router-redirect-urls

Conversation

@wobsoriano
Copy link
Copy Markdown
Member

Description

When configuring post-auth redirects via environment variables (CLERK_SIGN_IN_FALLBACK_REDIRECT_URL, CLERK_SIGN_IN_FORCE_REDIRECT_URL, and the sign-up equivalents), users land on a blank page after sign-in or sign-up and must refresh manually.

loadOptions reads all four redirect URL fields from env correctly, and getResponseClerkState references them when building __internal_clerk_state. But clerkMiddleware never forwarded them to getResponseClerkState, so they serialized as undefined on the client and the SignIn/SignUp components had no destination after completing auth.

This PR reafactors requestStateContext to carry both requestState and a new additionalState bag alongside it, rather than mutating the RequestState object returned by authenticateRequest (which we do not own).

additionalState holds the redirect URL options and keyless URLs. getResponseClerkState now accepts these as an explicit parameter instead of reading them off a mutated requestState. This mirrors the pattern used in @clerk/tanstack-react-start.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: c8a291f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/react-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
clerk-js-sandbox Skipped Skipped May 21, 2026 11:23pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 1640a43f-3c5c-4e9e-8448-0beb2b3452ed

📥 Commits

Reviewing files that changed from the base of the PR and between f0d309c and c8a291f.

📒 Files selected for processing (1)
  • packages/react-router/src/server/__tests__/rootAuthLoader.test.ts

📝 Walkthrough

Walkthrough

This PR refactors the Clerk React Router middleware to separate redirect URL and keyless URL configuration from the requestState object into a new additionalState payload. A new AdditionalStateOptions type aggregates keyless URLs and multiple redirect URL options. The requestStateContext now holds { requestState, additionalState } instead of just requestState. The middleware extracts these options from loadOptions and stores them in context without mutating requestState. Utility functions injectRequestStateIntoResponse and getResponseClerkState are updated to accept and use additionalStateOptions to derive redirect URL fields. The root auth loader threads additionalState through all state injection paths. Tests verify the context structure and the forwarding of redirect URL options.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: forwarding redirect URL options from middleware to client state, which directly addresses the bug fixed by this PR.
Description check ✅ Passed The description provides clear context on the bug (users landing on blank pages after auth), the root cause (redirect URLs not forwarded from middleware), and the solution (refactoring requestStateContext to carry additionalState).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 21, 2026

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@8622

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@8622

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@8622

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@8622

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8622

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@8622

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@8622

@clerk/express

npm i https://pkg.pr.new/@clerk/express@8622

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@8622

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@8622

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@8622

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@8622

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@8622

@clerk/react

npm i https://pkg.pr.new/@clerk/react@8622

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@8622

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@8622

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@8622

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@8622

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@8622

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@8622

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@8622

commit: c8a291f

@wobsoriano wobsoriano merged commit e1773ef into main May 22, 2026
43 checks passed
@wobsoriano wobsoriano deleted the rob/fix-react-router-redirect-urls branch May 22, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants